package com.zzy;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.loadbalancer.RandomRule;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

@SpringBootApplication
// 开启eureka客户端注解，可以不写
@EnableEurekaClient
// 开启熔断
@EnableCircuitBreaker
public class OrderApp {

    public static void main(String[] args) {
        SpringApplication.run(OrderApp.class, args);
    }

    @Bean // 相当于<bean>
    @LoadBalanced //让RestTemplate具有负载均衡能力，默认是轮询
    public RestTemplate restTemplate(){
        // localhost:10020   localhost:10021  本身RestTemplate并不知道怎么选
        return new RestTemplate();
    }

    @Bean // 配置负载均衡为随机算法
    public RandomRule randomRule(){
        return new RandomRule();
    }

}
